package com.ruoyi.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.OaResult;
import com.ruoyi.common.core.utils.facade.OaBusinessFacade;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.system.domain.OaRecruit;
import com.ruoyi.system.service.IOaRecruitService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 招聘需求Controller
 * 
 * @author ruoyi
 * @date 2020-12-29
 */
@RestController
@RequestMapping("/recruit")
public class OaRecruitController extends BaseController
{
    @Autowired
    private IOaRecruitService oaRecruitService;

    @PostMapping("/getRecruitRequest")
    public void getRecruitRequest()
    {
        OaResult result= OaBusinessFacade.getRecruitRequest();
        OaRecruit oaRecruit=new OaRecruit();
        oaRecruit.setCode(result.getCode());
        oaRecruit.setMessage(result.getMessage());
       // oaRecruit.setJdDescription();
      //  oaRecruit.setJdPath();
        oaRecruitService.insertOaRecruit(oaRecruit);

    }

    /**
     * 查询招聘需求列表
     */
    @PreAuthorize("@ss.hasPermi('system:recruit:list')")
    @GetMapping("/list")
    public TableDataInfo list(OaRecruit oaRecruit)
    {
        startPage();
        List<OaRecruit> list = oaRecruitService.selectOaRecruitList(oaRecruit);
        return getDataTable(list);
    }

    /**
     * 导出招聘需求列表
     */
    @PreAuthorize("@ss.hasPermi('system:recruit:export')")
    @Log(title = "招聘需求", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OaRecruit oaRecruit) throws IOException
    {
        List<OaRecruit> list = oaRecruitService.selectOaRecruitList(oaRecruit);
        ExcelUtil<OaRecruit> util = new ExcelUtil<OaRecruit>(OaRecruit.class);
        util.exportExcel(response, list, "recruit");
    }

    /**
     * 获取招聘需求详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:recruit:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(oaRecruitService.selectOaRecruitById(id));
    }

    /**
     * 新增招聘需求
     */
    @PreAuthorize("@ss.hasPermi('system:recruit:add')")
    @Log(title = "招聘需求", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OaRecruit oaRecruit)
    {
        return toAjax(oaRecruitService.insertOaRecruit(oaRecruit));
    }

    /**
     * 修改招聘需求
     */
    @PreAuthorize("@ss.hasPermi('system:recruit:edit')")
    @Log(title = "招聘需求", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OaRecruit oaRecruit)
    {
        return toAjax(oaRecruitService.updateOaRecruit(oaRecruit));
    }

    /**
     * 删除招聘需求
     */
    @PreAuthorize("@ss.hasPermi('system:recruit:remove')")
    @Log(title = "招聘需求", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(oaRecruitService.deleteOaRecruitByIds(ids));
    }
}
